<template>
<!-- ref  获取ref的dom -->
 <div class="list" ref="wrapper">
     <!-- 包裹一层 -->
   <div>
    <div class="area">
        <div class="title border-topbottom">当前城市</div>
        <div class="button-list">
            <div class="button-wrapper">
                <div class="button">{{this.currentCity}}</div>
            </div>
        </div>
    </div>
       <div class="area">
        <div class="title border-topbottom" >热门城市</div>
        <div class="button-list">
            <div class="button-wrapper" 
             v-for="hotCitieslist in hot" 
             :key="hotCitieslist.id" 
              @click="handleCityClick(hotCitieslist.name)"
              >
                <div class="button">{{hotCitieslist.name}}</div>
            </div>
            
        </div>
    </div>
    <div class="area" v-for="(citieslist,key) in cities" :key="key" :ref="key">
         <div class="title border-topbottom">{{key}}</div>
         <div class="item-list">
             <div class="item" v-for="innerItem in citieslist" :key="innerItem.id"    @click="handleCityClick(innerItem.name)">
                 {{innerItem.name}}
            </div>
            
         </div>
        
    </div>
  </div>  
 </div>
</template>

<script>
//滚动插件
import Bscroll from 'better-scroll'
import {mapState, mapMutations} from 'vuex'
 export default {
     computed :{
         ...mapState({
             currentCity:'city'
         })
     },
   props:{
       cities:Object,
       hot:Array,
       letter:String
   },
   data () {    
     return {

     }
   },
   methods :{
     
       handleCityClick(city){
           this.changeCity(city)
           this.$router.push('/')
       },
         ...mapMutations(['changeCity'])
   },
   components: {

   },
    
   //监听eventletter的变化
   watch :{
       letter () {
           if(this.letter){
               const element =   this.$refs[this.letter][0]
               
               this.scroll.scrollToElement(element)
           } 
       }
   },
   mounted () {
       this.scroll = new Bscroll(this.$refs.wrapper,{click:true})
   }
  }
</script>

<style lang="stylus" scoped> 

.list{
    position absolute
    top 78px 
    left 0
    overflow hidden
    right 0 
    bottom 0
}
.area{
 
}
    .border-topbottom{
            border-top 1px solid #cccccc
            border-bottom 1px solid #cccccc
        }
   .button-list{
        overflow hidden
        padding 5px 15px  5px 5px

   }
   .button-wrapper{
       width 33.33%
       float left 
   }
   .button{
       text-align center
       margin  10px
       padding 5px 0
       border  1px solid #ccc
   }
    .title{
        line-height 22px
        background #eee
        color #666
        
        padding-left 10px
    }
    .item-list{
        
    }
    .item{
        line-height 40px
        padding-left 10pxdev
        color #666
        border-bottom 1px solid #eee

    }
</style>

